#ifndef _RADIAN_AXIS_DRAWER_H_
#define _RADIAN_AXIS_DRAWER_H_

#include "RadianCommon.h"
#include "math/vector3.h"
#include "OgreVector2.h"
#include "OgreQuaternion.h"
#include "OgrePlane.h"

#include <QPointF>

/* This class handle the drawing of the axis.
*/
class RadianAxisDrawer
{
public:
	RadianAxisDrawer(RadianEditorController* parentController);
	virtual ~RadianAxisDrawer();

public:
	
	/* set edit mode.
	*/
	void SetEditMode(RadianEditMode editMode) { mEditMode = editMode; } 

	/* Update transfomation info.
	*/
	void Update();

	/* Handle mouse move event.
	*/
	bool OnMouseMove(QMouseEvent* evt);

	/* Handle mouse up event.
	*/
	bool OnMouseUp(QMouseEvent* evt);

	/* Handle mouse down event.
	*/
	bool OnMouseDown(QMouseEvent* evt);

	/* Initialize all the axis.
	*/
	void InitializeAxis();

	/* Update mouse position.
	*/
	void UpdateMousePosition(QPoint mousePos);

	/* Mouse test.
	*/
	bool MouseTest();

	/* Update axis colors.
	*/
	void UpdateAxisColors();

	Ogre::SceneNode* GetAxisNode() { return mAxisNode;}

protected:

	/* Do a move action.
	*/
	bool doMove(Ogre::Vector2 mousePos, Math::Vector3 dragNormal,Math::Vector3& moveDelta);

	/* Do a rotate action.
	*/
	bool doRotate();

	/* Do a scale action.
	*/
	bool doScale();

protected:
	bool mVisible;
	const static Ogre::Real MouseSensitivity;	// sensitivity of mouse move.
	const static Ogre::Real AxisLength;			// length of axis.
	const static Ogre::Real AxisWidth;			// width of axis.
	const static Ogre::Real AxisDleta;			// length of axis delta.
	const static Ogre::String XY_PlaneMeshName;	// xy dummy mesh name.
	const static Ogre::String XZ_PlaneMeshName; // xz dummy mesh name.
	const static Ogre::String YZ_PlaneMeshName; // yz dummy mesh name.

	Ogre::String mActiveMaterialName;			
	Ogre::String mInActiveMaterialName;


	RadianEditMode mEditMode;					// current edit mode.
	bool mIsXActive;					
	bool mIsYActive;
	bool mIsZActive;
	RadianEditorController* mParentController;	// parent controller.
	
	Math::Vector3 mEditCenter;					// current edit center.
	Math::Vector3 mEditScale;					// current edit scale.
	Ogre::Quaternion mEditRotation;				// current edit orientation.

	Math::Vector3 mEdgeX;
	Math::Vector3 mEdgeY;
	Math::Vector3 mEdgeZ;

	Ogre::ManualObject* mXAxis;					// x axis.
	Ogre::ManualObject* mYAxis;					// y axis.
	Ogre::ManualObject* mZAxis;					// z axis.

	Ogre::Plane xy_dummyPlane;
	Ogre::Plane xz_dummyPlane;
	Ogre::Plane yz_dummyPlane;

	Ogre::Entity* mPlane_xy;
	Ogre::Entity* mPlane_xz;
	Ogre::Entity* mPlane_yz;					

	Ogre::SceneNode* mAxisNode;					// scene node to attach axis.
	
	Ogre::Vector2 mMousePosition;				// mouse position.
	QPointF mLastMousePosition;					// last mouse position.
	bool mIsOnDragging;

};
#endif